home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / C++ AppleLink Messages / CPlus.Dev$ 3⁄30⁄90 / 0092-Screaming Free Store-Mar90 < prev    next >
Encoding:
Text File  |  1990-03-30  |  3.6 KB  |  134 lines  |  [TEXT/GEOL]

  1. Item    2524183                         27-March-90        23:30PST
  2.  
  3. From:   D0532                           Aidea Systems, Don Park,PRT
  4.  
  5. To:     CPLUS.DEV$                      C++ Interest List--Developers
  6.         CPLUS.APPLE$                    C++ Interest List--Apple Employees
  7.  
  8. Sub:    Screaming Free Store!!!
  9.  
  10. Hello, folks!
  11.  
  12. I have been concerned about the speed of default C++ free store mechanism, so I
  13. wrote my own free store mechanism which I call 'Arena'.  Having written it, I
  14. wanted to see how it compared with other mechanisms, so I wrote a set of
  15. programs which simply allocates 100 integer objects 100 times.  I think the
  16. test is a good representation of a graphics oriented application in which
  17. thousands objects have to be generated practically instantly to represent
  18. various path elements of sophisticated drawing.
  19.  
  20. Following are the mechanism I have tested:
  21.  
  22. 1.  NewPtr/DisposPtr        // Direct calls to Memory Manager
  23. 2.  HandleObject            // Deriving from HandleObject
  24. 3.  new/delete              // Standard free store mechanism
  25. 4.  malloc/free             // Direct calls to StdLib
  26. 5.  Arena                   // My own mechanism
  27.  
  28. Following are the results of those tests on Mac IIcx:
  29.  
  30. 1.  NewPtr/DisposPtr = 461 ticks
  31. 2.  HandleObject     = 128 ticks
  32. 3.  new/delete      = 109 ticks
  33. 4.  malloc/free     =  85 ticks
  34. 5.  Arena         =  15 ticks
  35.  
  36. One would think that by overriding new/delete with calls to NewPtr/DisposPtr
  37. would increase the speed of free store object allocation, but it turns out that
  38. NewPtr/DisposPtr is the slowest of them all, taking over 4 times more time than
  39. default new/delete code.  HandleObject for some reason was much better, only
  40. slightly slower than new/delete.  Fact that NewPtr/DisposPtr takes longer than
  41. HandleObject is certainly strange.  However it is not strange to find
  42. malloc/free somewhat faster than new/delete since the later uses calloc/free.
  43.  
  44. Well, I am quite satisfied with the result of the test.  Arena is over 7 times
  45. faster than the standard new/delete mechanism.  I am planning to use it in few
  46. places where it demands nose bleeding speed.
  47.  
  48. Please do not be despaired if you think you are stuck with the standard
  49. new/delete mechanism.  I am sure you guys can also come up with your own
  50. mechanisms but the important thing is that you should not sit on your you know
  51. what and rely on the standard mechanism.
  52.  
  53. Don Park
  54.  
  55. P.S.  Test program source follows:
  56.  
  57. #if    NewPtrFreeStore
  58.  
  59.     class IntObj
  60.     {
  61.     public:
  62.         void *    operator new ( size_t sz )
  63.         {
  64.             return NewPtr((Size)sz);
  65.         }
  66.         void    operator delete ( void * dp )
  67.         {
  68.             DisposPtr((Ptr)dp);
  69.         }
  70.         int        i;
  71.     };
  72.  
  73. #elif    HandleObjectFreeStore
  74.  
  75.     class IntObj : HandleObject
  76.     {
  77.         int        i;
  78.     };
  79.  
  80. #elif    DefaultFreeStore
  81.  
  82.     class IntObj
  83.     {
  84.         int        i;
  85.     };
  86.  
  87. #elif    MallocFreeStore
  88.  
  89.     class IntObj
  90.     {
  91.     public:
  92.         void *    operator new ( size_t sz )
  93.         {
  94.             return (void*)malloc(sz);
  95.         }
  96.         void    operator delete ( void * dp )
  97.         {
  98.             free(dp);
  99.         }
  100.         int        i;
  101.     };
  102.  
  103. #elif    ArenaFreeStore
  104.  
  105.     class IntObj : public AxArenaObject
  106.     {
  107.         int        i;
  108.     };
  109.  
  110. #endif
  111.  
  112. const NI = 100;
  113. const NJ = 100;
  114.  
  115. IntObj *    iobj[NJ];
  116.  
  117. main ()
  118. {
  119.     long    tick;
  120.     int        i, j;
  121.  
  122.     tick = TickCount();
  123.     for (i = 0; i < NI; i++)
  124.     {
  125.         for (j = 0; j < NJ; j++)
  126.             iobj[j] = new IntObj;
  127.         for (j = 0; j < NJ; j++)
  128.             delete iobj[j];
  129.     }
  130.     tick = TickCount() - tick;
  131.     cout << tick << '\n';
  132. }
  133.  
  134.